// pages/order/index.js
const {http}=require("../../utils/http");
const {orderDelete}=require("../../utils/insertAndDelete");
Page({
  data: {
    order:[]
  },
  onLoad: function (options) {
    var url="http://122.112.245.197:5000/api/order";
    http({
      url,
      success:(res)=>{
        var order=[];
        res.data.forEach(item=>{
          if(!wx.getStorageSync('iphone')){
            return false;
          }
          else if(item.userID==wx.getStorageSync('iphone')){
            order.push(item);
          }
        })
        this.setData({
          order:order
        })
      }
    })
  },
  delete(e){
    console.log(e.currentTarget.dataset.aid)
    var data={
      cart:e.currentTarget.dataset.aid.cart,
      totalPrice:e.currentTarget.dataset.aid.totalPrice,
      userID:e.currentTarget.dataset.aid.userID,
      address:e.currentTarget.dataset.aid.address
    }
    orderDelete({
      data,
      success:(res)=>{
        wx.showToast({
          title: '删除成功',
        })
        this.onLoad();
      }
    })
  }
})